/*
 * Copyright Aristool AG Switzerland
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package org.opprua.tidy.conversion;

import java.util.Date;

import org.opprua.tidy.util.TimePoint;

/**
 * TODO: add Java doc
 * 
 * Prepared for first commit: 15.07.2007
 * 
 * @author Lin Li
 */
class CTDate extends ChangeType<Date> {

  private SingleChanger<Date>[] changers = null;

  private static class MyDate extends SingleChanger<Date> {

    public MyDate(Class<?> c) {
      super(c);
    }

    public Date change(Object data) {
      return TimePoint.from(data).getDate(Date.class);
    }
  }

  public CTDate() {
    super(Date.class, new Date(0L));
  }

  @Override
  @SuppressWarnings("unchecked")
  public SingleChanger<Date>[] getchangers() {
    if (changers == null) {
      changers = new MyDate[] {
                  new MyDate(String.class), new MyDate(java.sql.Date.class),
                  new MyDate(java.sql.Time.class), new MyDate(java.sql.Timestamp.class),
                  new MyDate(Long.class) };
    }
    return changers;
  }
}